package com.xyd.service;

import com.xyd.util.OutOfStockException;
import org.springframework.stereotype.Component;

@Component("phoneBiz")
public class PhoneBizImpl implements PhoneBiz {
    int num; //库存

    @Override
    public void buyPhone(int num) {
        System.out.println("手机进货，数量为：" + num + "部");
        this.num = num;
    }

    @Override
    public void salPhone(int num) throws OutOfStockException {
        if (this.num < num) {
            throw new OutOfStockException("库存不足，需要" + num + "台，库存只有" + this.num + "台");
        }

        System.out.println("手机销售，数量为：" + num + "部");
    }
}
